<style>
    body {
        background: #f5f5f5;
    }
</style>
<div class="sectionY">
    <a href="javascript:history.back()">
        <img src="__PUBLIC__/home/images/a4.png" class="a1" alt="">
    </a>
    <p class="p1">收货地址</p>
    <a href="javascript:addAddress();" class="a3">新建</a>
</div>
<div class="kong1"></div>
<div class="dihzi_section1">
    {if !empty($list)}
    {foreach $list as $item}
    <div class="list clearfix">
        <div class="center sel_{$item._id}" onclick="selecteAddress('{$item._id}')">
            <p class="p1">
                <span class="s1">{$item.name}</span>
                <span class="s2">{$item.mobile|show_star}</span>
                {if $item.is_def eq 1}
                <span class="s3">默认</span>
                {/if}
            </p>
            <p class="p2 chao">
                <img src="__PUBLIC__/home/images/a48.png" alt="">
                <span class="s1">{$item.pro_name} {$item.city_name} {$item.area_name} {$item.address}</span>
            </p>
        </div>
        <div class="right" onclick="goEditAddress('{$item._id}')">
            <a href="javascript:;">
                <img src="__PUBLIC__/home/images/a49.png" alt="">
            </a>
        </div>
    </div>
    {/foreach}
    {else/}
    <div id="no_msg" style="display: block;">暂无收货地址</div>
    {/if}
</div>

<script>
    var redirect_url = "{$redirect_url}";
    function addAddress() {
        if(redirect_url != ""){
            location.href = "{:url('User/addAddress')}?redirect_url="+redirect_url;
        }else{
            location.href = "{:url('User/addAddress')}";
        }
    }

    function goEditAddress(address_id) {
        if(redirect_url != ""){
            location.href = "{:url('User/editAddress')}?redirect_url="+redirect_url+"&address_id="+address_id;
        }else{
            location.href = "{:url('User/editAddress')}?address_id="+address_id;
        }
    }

    function selecteAddress(address_id) {
        if(redirect_url != ""){
            var obj = $(".sel_"+address_id);
            modal.ajax("{:url('Order/changeAddress')}",{address_id:address_id},function (res) {
                if(res.result_code==0){
                    window.history.back();
                }else{
                    modal.msg(res.info);
                }
            },function (e) {
                console.log(e);
            });
        }else{
            location.href = "{:url('User/editAddress')}?address_id="+address_id;
        }
    }

</script>